﻿using MediatR;
using System.CJL.API.Application.Command.FinishedProductsCommand;
using System.CJL.Infrstructre.Interface;

namespace System.CJL.API.Application.CommandHanlder.FinishedProductsCommandHanler
{
	/// <summary>
	/// 批量删除
	/// </summary>
	public class FinishedProductsDeletePiCommandHandler:IRequestHandler<FinishedProductsDeletePiCommand,int>
	{
		IFinishedProductRepositry _repositry;
		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name="repositry"></param>
        public FinishedProductsDeletePiCommandHandler(IFinishedProductRepositry repositry)
        {
			_repositry=repositry;
		}
		/// <summary>
		/// 批量删除
		/// </summary>
		/// <param name="request"></param>
		/// <param name="cancellationToken"></param>
		/// <returns></returns>
		/// <exception cref="NotImplementedException"></exception>
		public async Task<int> Handle(FinishedProductsDeletePiCommand request, CancellationToken cancellationToken)
		{
			var result = (await _repositry.GetAll()).Where(x => request.id.Contains(x.finishedProductId));
			foreach (var item in result)
			{
				item.IsDelete = true;
				item.DelectName = "张三";
				item.DelectTime = DateTime.Now.ToUniversalTime();
				await _repositry.UpdateAsync(item);
			}
			return 1;

		}
	}
}
